/**
 * Copyright 2011 Joe Choi, All rights reserved.
 */
package tao.calendar.gregorian.util;

import java.util.*;

import tao.calendar.gregorian.GregorianDateTime;
import static tao.calendar.gregorian.Gregorian.*;

/**
 * The GlobalDateTime is used to handle date and time with TimeZone
 * <br><br>
 * Actually, the GlobalDateTime is a demonstration of use of tao.calendar.gregorian package.
 * It simplify the manipulation of time with different time zone
 * 
 * @author Joe Choi
 * @version 1.0.0
 * @see java.util.TimeZone
 * @see java.util.Locale
 */
public class GlobalDateTime {
	public GlobalDateTime(GregorianDateTime dt) {
		this(Locale.getDefault(), TimeZone.getDefault(), dt);
	}
	
	public GlobalDateTime(Locale locale, GregorianDateTime dt) {
		this(locale, TimeZone.getDefault(), dt);
	}
	
	public GlobalDateTime(TimeZone zone, GregorianDateTime dt) {
		this(Locale.getDefault(), zone, dt);
	}
	
	public GlobalDateTime(Locale locale, TimeZone zone, GregorianDateTime dt) {
		this.locale = locale;
		this.calendar = toCalendar(dt, zone, locale);
	}

	@Override
	public String toString() {
		return(calendar.toString());
	}
	
	@Override
	public boolean equals(Object obj) {
		if(! (obj instanceof GlobalDateTime)) return(false);
		GlobalDateTime other = (GlobalDateTime) obj;
		return(	this.calendar.equals(other.calendar) );
	}
	
	@Override
	public int hashCode() { 
		return(calendar.hashCode()); 
	}

	public GlobalDateTime changeTimeZone(TimeZone zone) {
		Calendar tmp = Calendar.getInstance(zone, locale);
		tmp.setTimeInMillis(calendar.getTimeInMillis());
		calendar = tmp;
		return(this);
	}
	
	public GregorianDateTime getDateTime() {
		return(dateTime(calendar));
	}

	public TimeZone getTimeZone() {
		return(calendar.getTimeZone());
	}
	
	public Locale getLocale() {
		return(locale);
	}
	
	private Locale locale;
	private Calendar calendar;
}
